<#include "/common/defaultEngine.html"/>
<@pageTheme mark="${config.optimize()?string('true', 'false')}">
<@header title="序列号" libs=["table"]/>
<div class="container-div" id="_app">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <@f.form id="module-form">
            <div class="select-list">
                <ul>
                    <li >
                        <label>编号： </label>
                        <@f.input id="projectCode" name="sampleCode"/>
                    </li>
                    <li>
                        <@ctx.i18n text = "项目名字"/>：
                        <input type="text" class="form-control" name="projectName"/>
                    </li>

                    <li>
                        <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>  <@ctx.i18n text = "查询"/></a>
                        <a class="btn btn-warning btn-rounded btn-sm" onclick="opt.form.reset()"><i class="fa fa-refresh"></i> <@ctx.i18n text = "重置"/></a>
                    </li>
                </ul>
            </div>
        </@f.form>
    </div>
        <@table id="bootstrap-table">
            <@shiro.hasPermission name="code:serial:add">
            <a class="btn btn-success" onclick="opt.operate.add(0)"><i class="fa fa-plus"></i>&nbsp;<@ctx.i18n text = "新增"/></a>
            </@shiro.hasPermission>
            <@shiro.hasPermission name="code:serial:edit">
            <a class="btn btn-primary single disabled" onclick="opt.operate.edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;<@ctx.i18n text = "修改"/></a>
            </@shiro.hasPermission>
            <@shiro.hasPermission name="code:serial:del">
            <a class="btn btn-danger multiple disabled" onclick="opt.operate.delAll()">
                <i class="fa fa-remove"></i> <@ctx.i18n text = "删除"/>
            </a>
            </@shiro.hasPermission>
        </@table>
    </div>
</div>
<@footer>
<script type="text/javascript">
     var statusDatas = ${dict.getDictListJson('sys_user_show_hide')};
    var editFlag = "${permission.hasPermi("code:serial:edit")}";
    var listFlag = "${permission.hasPermi("code:serial:add")}";
    // var categoryDatas = ${dict.getDictListJson('sys_bpm_category')};
    var prefix = baseURL + "code/serial";

    $(function() {
        var options = {
            url: prefix + "/list",
            // showSearch: false,
            // showRefresh: false,
            // showToggle: false,
            // showColumns: false,
            clickToSelect: true,
            sortName: "id",
            delUrl: prefix + "/del",
            addUrl: prefix + "/add",
            editUrl: prefix + "/edit/{id}",//认领箱
            exportUrl: prefix + "/export",
            importUrl: prefix + "/import",
            uniqueId: 'id' , /* 唯一ID */
            modalName: "序列号管理",
            columns: [
                // {field: 'selectItem', radio: true},
                {title: $.i18n.prop("序号"), width: 5, align: "center", formatter: function (value, row, index) {
                        return $.table.serialNumber(index);}},
                // {field : 'id',title : '<@ctx.i18n text = "编号"/>'},
                {field : 'codeType',title : '<@ctx.i18n text = "编号类型"/>'},
                {field : 'name',title : '<@ctx.i18n text = "名称"/>'},
                {field : 'codeRule',title : '<@ctx.i18n text = "编号规则"/>'},
                {field : 'state',title : '<@ctx.i18n text = "状态"/>',formatter: function(value, row, index) {
                    return $.table.selectDictLabel(statusDatas, value);}},

                {field : 'remark',title : '<@ctx.i18n text = "备注"/>'},

                //     {field : 'id',title : ''},

                // {title:"<@ctx.i18n text = "操作"/>",align: 'left',class:'action',formatter: function(value, row, index) {
                //         var actions = [];
                //         // actions.push('<a class="" href="javascript:void(0)" title="<@ctx.i18n text = "关联流程表单"/>" onclick="taskFrom(\'' + row.id + '\')"><i class="fa icon-organization"></i></a> ');
                // //        actions.push('<a class="" href="javascript:void(0)" title="<@ctx.i18n text = "认领修改"/>" onclick="taskFromEdit(\'' + row.id + '\')">认领修改</a> ');
                //         actions.push('<a class="" href="javascript:void(0)" title="<@ctx.i18n text = "出库"/>" onclick="checkout(\'' + row.id + '\')">出库</a> ');
                //         return actions.join('');
                // }}
            ]
        };
        $.table.init(options);
    });

    function checkout(id){
        console.log("1111111111");
        console.log(id);
        console.log("11111111");
        // opt.layer.open({
        //     type: 1,
        //     area: ['400px', '180px'],
        //     title: '<i class="fa fa-upload"></i> 出库 </i>',
        //     shade: 0.3,
        //     shadeClose: true,
        //     resize: false,
        //     scrollbar: true,
        //       // content: opt.template('check'),
        //  //   content: opt.template('check'),
        //     btn: ['<i class="fa fa-check"></i> 出库',
        //         '<i class="fa fa-remove"></i> 取消'],
        //     btn1: function(index, layero){
        //         // var form = {
        //         //     inputForm: layero.find('#inputForm'),
        //         //     f: layero.find('#f').val()
        //         // };
        //
        //         // var formdata = new FormData();
        //         // var file = layero.find('#f')[0].files[0];
        //         // formdata.append("files", file);
        //         opt.common.sendAjax({
        //             url: prefix + "/checkout",
        //             data: id,
        //             type: "POST",
        //             processData: false,
        //             contentType: false,
        //             success: function(result) {
        //                 if(result.code == opt.variable.web_status.SUCCESS){
        //                     opt.layer.closeAll();
        //                     opt.success("<@ctx.i18n text = "出库成功!"/>");
        //                     location.reload();
        //                 }else{
        //                     opt.error(result.msg);
        //                 }
        //             }
        //         });
        //         return true;
        //     }
        // });
        opt.modal.confirm("确认出库吗?", function() {
            opt.operate.post(prefix + "/checkout", { "id": id});
        })
    }


    /* 用户管理-重置密码 */
    function upload() {
        var options = {
            title: "选择文件",
            width: "800",
            height: "300",
            url: prefix + '/selectFile',
            callBack: DeptDoSubmit
        };
        opt.modal.openOptions(options);
    }

    function DeptDoSubmit(index, layero) {

        var body = layer.getChildFrame('body', index);
        console.log(body);
        importTable(body.find('#fileName').val());
        layer.close(index);
    }

    /*导入表结构*/
    function importTable(url) {

        var importTableUrl = prefix + "/upload/";

        /*opt.modal.open("导入表结构", importTableUrl);*/
        opt.operate.post(importTableUrl,{url: url});
    }






    function upload_abort(){
        document.getElementById("files").click();
        if(files == ""){
            alert("请选择要上传的文件");
        }else{
            //扩展名的文件名
            var files = document.getElementById("files").value;
            //扩展名的文件名
            var bbb=files.lastIndexOf(".");
            var ccc=files.substring(bbb+1);
            if(ccc=='xlsx'){
                $("#uploadForm").submit();
                setTimeout("fun()",1500);
            }else{
                alert("请选择.xlsx文件");
            }
        }


    }


    /* 挂起流程定义 */
    function disable(id) {
        opt.modal.confirm("确认要挂起流程定义吗？", function() {
            opt.operate.post(prefix + "/status", { "deploymentId": id, "status": 1 });
        })
    }

    /* 激活流程定义 */
    function enable(id) {
        opt.modal.confirm("确认要激活流程定义吗?", function() {
            opt.operate.post(prefix + "/status", { "deploymentId": id, "status": 0 });
        })
    }

    function taskFromEdit(id) {
        // opt.modal.confirm("确认要删除流程定义吗?", function() {
        //  opt.modal.openTab(prefix + "/edit", { "id": id});
        console.log("1111111111");
        console.log(id);
        console.log("11111111");
        opt.modal.openTab("认领修改",prefix + "/edit/"+id);
        // })
    }

    function taskFrom(id){


        opt.modal.openTab("关联表单",prefix + "/taskfrom/"+id);
    }

    /*预览*/
    function preview(id) {
        var options = {
            url: prefix + "/preview/" + id,
            title: '<i class="fa icon-picture"></i> <@ctx.i18n text = "流程图"/>',
            btn:['<i class="fa fa-close"></i> '+$.i18n.prop("取消")],
            width: $(top.window).width() - 300,
            height: $(top.window).height() - 400
        };
        opt.modal.openMainWin(options);
    }

    /*预览XML*/
    function  preXml(id){
        var options = {
            url: prefix + "/xml/" + id,
            title:'<i class="fa fa-file-code-o"></i> <@ctx.i18n text = "BPMN2.0流程文件"/>',
            btn:['<i class="fa fa-close"></i> '+$.i18n.prop("取消")],
        };
        opt.modal.openMainWin(options);
    }

    /*生成代码*/
    function xmlDownload(id,name) {
        opt.modal.confirm("确定要下载[" + name + "]流程文件吗?", function() {
            location.href = prefix + "/download/" + id;
            opt.modal.msg('执行成功,正在下载请稍后…');
        })
    }
    $('#licSelect').click(function(){
        opt.layer.open({
            type: 1,
            area: ['580px', '180px'],
            title: '<i class="fa fa-upload"></i> 导入文件 <i class="fa fa-info-circle" style="color: red"></i>!',
            shade: 0.3,
            shadeClose: true,
            resize: false,
            scrollbar: true,
            content: opt.template('upload'),
            btn: ['<i class="fa fa-check"></i> 上传',
                '<i class="fa fa-remove"></i> 取消'],
            btn1: function(index, layero){
                var form = {
                    inputForm: layero.find('#inputForm'),
                    f: layero.find('#f').val()
                };
                if (form.f == '' || !opt.common.endWith(form.f, '.xlsx'||!opt.common.endWith(form.f, '.xls'))){
                    opt.warning("<@ctx.i18n text = "文件不正确，请选择后缀为 . xls和xlsx的文件。"/>");
                    return false;
                }
                var formdata = new FormData();
                var file = layero.find('#f')[0].files[0];
                formdata.append("files", file);
                opt.common.sendAjax({
                    url: prefix + "/upload",
                    data: formdata,
                    type: "POST",
                    processData: false,
                    contentType: false,
                    success: function(result) {
                        if(result.code == opt.variable.web_status.SUCCESS){
                            opt.layer.closeAll();
                            opt.success("<@ctx.i18n text = "文件上传成功!"/>");
                            location.reload();
                        }else{
                            opt.error(result.msg);
                        }
                    }
                });
                return true;
            }
        });
    });
</script>

</@footer>
</@pageTheme>